package com.yb.xczx.cloud.system.config;

import com.yb.xczx.cloud.system.constant.RabbitConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Copyright (C), 2022-2022, 姚兵
 * Author: 32210
 * Date: 2022/9/16 12:45
 * FileName: RabbitQueueConfig
 * Description: 123
 */
@Configuration
public class RabbitQueueConfig {

    @Bean
    public Queue demo1(){
        return new Queue(RabbitConstant.DemoQueue.DEMO_QUEUE,false);
    }

    @Bean
    public DirectExchange demoExchange(){
       return ExchangeBuilder.directExchange(RabbitConstant.DemoQueue.DEMO_EXCHANGE).build();
    }

    @Bean
    Binding demoBinding(){
     return   BindingBuilder.bind(demo1()).to(demoExchange()).with(RabbitConstant.DemoQueue.DEMO_ROUTING_KEY);
    }

    @Bean
    public Queue fanoutQueue(){
        return new Queue(RabbitConstant.FanoutQueue.QUEUE_NAME,true);
    }

    @Bean
    public Queue fanoutQueue1(){
        return new Queue(RabbitConstant.FanoutQueue.QUEUE_NAME_1,true);
    }

    @Bean
    public FanoutExchange fanoutExchange(){
        return ExchangeBuilder.fanoutExchange(RabbitConstant.FanoutQueue.EXCHANGE_NAME).build();
    }

    @Bean
    Binding fanoutBuilder(){
        return BindingBuilder.bind(fanoutQueue()).to(fanoutExchange());
    }


    @Bean
    Binding fanoutBuilder1(){
        return BindingBuilder.bind(fanoutQueue1()).to(fanoutExchange());
    }
}
